/*-
 * Copyright (c) 2006, 2007 FTS Team
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the FTS Team nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *      SafePtr.hpp
 *
 * $FTS$
 */
#ifndef _SAFE_PTR_HPP__
#define _SAFE_PTR_HPP__ 1

/**
  @file SafePtr.hpp
  @brief Safe semi-smart pointer
*/

namespace FTSS // FullTextSearchSystem
{

/**
  @class SafePtr SafePtr.hpp <SafePtr.hpp>
  @brief Safe semi-smart pointer
*/
template <typename T>class SafePtr
{
private:
	/** Pointer which need to be safe */
	T * pT;

	/**
	  @brief Private constructor
	*/
	SafePtr();

	/**
	  @brief Private copy constructor
	  @param oRhs - object to copy
	*/
	SafePtr(const SafePtr & oRhs);

	/**
	  @brief Private copy operator
	  @param oRhs - object to copy
	  @return pointer to self
	*/
	SafePtr & operator=(const SafePtr & oRhs);

public:
	/**
	  @brief Constructor
	  @param pIT - pointer to the object
	*/
	inline SafePtr(T * pIT) throw(): pT(pIT) { ;; }

	/**
	  @brief A destructor, destruct only one object
	*/
	inline ~SafePtr()       throw() { delete pT; }

	/**
	  @brief Pointer operator
	  @return pointer to the object
	*/
	inline T * operator->() throw() { return pT; }

	/**
	  @brief Oprtator ()
	  @return pointer to the object
	*/
	inline T * operator()() throw() { return pT; }
};

/**
  @class SafeArrayPtr SafePtr.hpp <SafePtr.hpp>
  @brief Safe semi-smart pointer for arrays
*/
template <typename T>class SafeArrayPtr
{
private:
	/** Pointer which need to be safe */
	T * pT;

	/**
	  @brief Private constructor
	*/
	SafeArrayPtr();

	/**
	  @brief Private copy constructor
	  @param oRhs - object to copy
	*/
	SafeArrayPtr(const SafeArrayPtr & oRhs);

	/**
	  @brief Private copy operator
	  @param oRhs - object to copy
	  @return pointer to self
	*/
	SafeArrayPtr & operator=(const SafeArrayPtr & oRhs);

public:
	/**
	  @brief Constructor
	  @param pIT - pointer to the object
	*/
	inline SafeArrayPtr(T * pIT) throw(): pT(pIT) { ;; }

	/**
	  @brief A destructor, destruct array of objects
	*/
	inline ~SafeArrayPtr()  throw() { delete [] pT; }

	/**
	  @brief Pointer operator
	  @return pointer to the object
	*/
	inline T * operator->() throw() { return pT; }

	/**
	  @brief Oprtator ()
	  @return pointer to the object
	*/
	inline T * operator()() throw() { return pT; }
};

} // namespace FTSS
#endif // _SAFE_PTR_HPP__
// End.
